package com.gk.util.component
{
	import flash.display.Sprite;
	import flash.text.TextField;
	import flash.text.TextFormat;
	
	/**
	 *UI的静态公共方法类 
	 * @author Nestor
	 * 
	 */	
	public final class UICommon
	{
		public function UICommon()
		{
		}
		/**
		 *画一个矩形 
		 * @param w
		 * @param h
		 * @param lineColor
		 * @param fillColor
		 * @param lineSize
		 * @param alpha
		 * @return 
		 * 
		 */
		public static function getRectGraphic(w:int,
											  h:int,
											  lineColor:uint,
											  fillColor:uint,
											  lineSize:int=1,
											  lineAlpha:Number=1,
											  fillAlpha:Number=1):Sprite {
			var sp:Sprite = new Sprite(); 
			sp.graphics.lineStyle(lineSize, lineColor, lineAlpha);
			sp.graphics.beginFill(fillColor, fillAlpha);
			sp.graphics.drawRect(0,0,w,h);
			sp.graphics.endFill();
			return sp;
		}
		
		/**
		 * 处理文本
		 * @param tf
		 * @param w
		 * @param h
		 * @param autoSize
		 * @param wordWap
		 * @param textColor
		 * @param size
		 * @return 
		 * 
		 */
		public static function processTextField(tf:TextField, 
												textColor:uint=0xff0000,
												w:int=0,
												h:int=0,
												autoSize:String="left",
												wordWap:Boolean=false
		):TextField {
			if(w != 0) {
				tf.width = w;
			}
			if(h != 0) {
				tf.height = h;
			}
			tf.textColor = textColor;
			tf.autoSize = autoSize;
			tf.wordWrap = wordWap;
			return tf;
		}
		
		
		/**
		 *创建文本 
		 * @param defaultTxt
		 * @param textColor
		 * @param w
		 * @param h
		 * @param autoSize
		 * @param wordWap
		 * @param enable
		 * @return 
		 * 
		 */		
		public static function getTextField(defaultTxt:String = "",
											textColor:uint=0xff0000,
											w:int=0,
											h:int=0,
											autoSize:String="left",
											wordWap:Boolean=false,
											enable:Boolean = false,
											bold:Boolean = false):TextField {
			var tf:TextField = new TextField();
			tf.text = defaultTxt;
			if(w != 0) {
				tf.width = w;
			}
			if(h != 0) {
				tf.height = h;
			}
			tf.textColor = textColor;
			tf.autoSize = autoSize;
			tf.wordWrap = wordWap;
			tf.mouseEnabled = enable;
			var txtFmt:TextFormat = new TextFormat();
			txtFmt.bold = bold;
			tf.setTextFormat(txtFmt);
			return tf;
		}
		
		/**
		 * 画均匀网格
		 * @param w
		 * @param h
		 * @param rows
		 * @param cols
		 * @param lineClor
		 * @param lineSize
		 * @param lineAlpha
		 * 
		 */
		public static function drawGrid(w:int, 
										h:int,
										rows:int,
										cols:int,
										lineClor:uint,
										lineSize:Number=1,
										lineAlpha:Number=1):Sprite {
			var sp:Sprite = new Sprite();
			var rowSize:int = Math.round(h/rows);
			var colSize:int = Math.round(w/cols);
			sp.graphics.lineStyle(lineSize, lineClor, lineAlpha);
			var i:int;
			var j:int;
			for(i=0; i<=rows; i++) {
				sp.graphics.moveTo(0, i*rowSize);
				sp.graphics.lineTo(w, i*rowSize);
			}
			for(i=0; i<=cols; i++) {
				sp.graphics.moveTo(i*colSize, 0);
				sp.graphics.lineTo(i*colSize, rowSize*rows);
			}
			return sp;
		}
	}
}